package com.info33.platform.config.shiro;

import com.info33.platform.common.enums.LoginType;
import com.info33.platform.config.shiro.token.UserToken;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;

import java.util.Arrays;

/**
 * @author debj
 * @version 1.0
 * @date 2021/7/26 17:55
 */
public class MyCredentialsMatcher extends HashedCredentialsMatcher {

    /**
     * 免密登录重写校验方式
     *
     * @param token -
     * @param info  -
     * @return -
     */
    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        UserToken userToken = (UserToken) token;
        if (Arrays.asList(LoginType.SYS_MESSAGE,
                        LoginType.APP_MESSAGE,
                        LoginType.SYS_QR_CODE,
                        LoginType.M_APP_MESSAGE)
                .contains(userToken.getLoginType())) {
            return true;
        }
        return super.doCredentialsMatch(token, info);
    }
}